<template>
    <el-card class="outer" shadow="never">
        <div class="title">
            <p>数据统计</p>
            <el-tooltip effect="dark" placement="top-start">
                <template #content>
                    <div class="channel-code-stat-base-tooltip-content">
                        <p>指标说明：</p>
                        <p v-for="item in overview" :key="item">{{ item?.label }}：{{ item?.tip }}</p>
                        <div>
                            注意：
                            <p>1、各指标统计数据不包含今日数据。</p>
                            <p>2、如果一个客户通过该活码添加了其中的两位员工，“去重”计为1，“不去重”则计为2。</p>
                        </div>
                    </div>
                </template>
                <el-icon class="box-icon">
                    <QuestionFilled />
                </el-icon>
            </el-tooltip>
        </div>
        <div class="container-box">
            <div class="container">
                <div v-for="item in overview" :key="item" class="total-item">
                    <p class="total-name">{{ item.label }}</p>
                    <p class="total-num">{{ numFormat(peopleNum[item.numStr]) }}</p>
                </div>
            </div>
            <div class="container">
                <div v-for="item in todayData" :key="item" class="today-box">
                    <p class="today-item">{{ item.label }}：{{ numFormat(todyNum[item.numStr]) }}</p>
                </div>
            </div>
        </div>
    </el-card>
</template>
<script lang="ts" setup>
import { ref, watch } from 'vue';
import { numFormat } from '@/utils/utils';

const props = defineProps(['basicData']);
// 数据概览总数据
const peopleNum = ref<any>({
    get_cust_qty: null
});
const todyNum = ref<any>({}); // 今天数据
const overview = ref([
    { label: '获客数', tip: '通过该渠道活码添加的企微客户数（去重），包含该渠道流失的客户；', numStr: 'get_cust_qty' },
    {
        label: '流失客户数',
        tip: '通过该渠道活码添加的企微客户又删除了该活动所有引流员工（包括历史去除的员工）的客户数（去重），注：此处删除的定义是指客户删员工或员工删客户，或者两者互删；',
        numStr: 'loss_cust_qty'
    },
    { label: '留存客户数', tip: '获客数-流失客户数；', numStr: 'retain_cust_qty' },
    {
        label: '添加好友数',
        tip: '通过该渠道活码添加的好友数（不去重），包含其中删除员工的好友；',
        numStr: 'add_friend_qty'
    },
    {
        label: '删除好友数',
        tip: '通过该渠道活码添加的好友又删除了该活码引流员工的好友数（不去重）；',
        numStr: 'del_friend_qty'
    },
    { label: '留存好友数', tip: '添加好友数-删除好友数。', numStr: 'retain_friend_qty' }
]);
const todayData = ref([
    { label: '今日获客', numStr: 'get_cust_qty' },
    { label: '今日流失', numStr: 'loss_cust_qty' },
    { label: '今日留存', numStr: 'retain_cust_qty' },
    { label: '今日添加', numStr: 'add_friend_qty' },
    { label: '今日删除', numStr: 'del_friend_qty' },
    { label: '今日留存', numStr: 'retain_friend_qty' }
]);
watch(
    () => props.basicData,
    vla => {
        peopleNum.value = vla.summary || {};
        todyNum.value = vla.today || {};
    }
);
</script>

<style lang="scss" scoped>
:deep(.el-card__body) {
    padding: 0;
}

.outer {
    margin-top: 16px;
    padding: 0;
    border-bottom: 2px solid #ffc69e;

    .title {
        display: flex;
        align-items: center;
        padding: 17px 24px;
        border-bottom: 1px solid #eaeaea;

        :deep(.box-icon) {
            text-align: center;
            font-size: 16px;
            margin-left: 4px;
            color: #ccc;
            background: #fff;
        }
    }

    .container-box {
        padding: 17px 24px;

        .container {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
            grid-row-gap: 32px;
            align-items: center;

            .total-item {
                .total-name {
                    font-size: 14px;
                    font-family: PingFangSC-Regular, 'PingFang SC';
                    font-weight: 400;
                    color: #666;
                    margin-bottom: 8px;
                }

                .total-num {
                    font-size: 24px;
                    line-height: 24px;
                    font-family: HelveticaNeue-Medium, HelveticaNeue;
                    font-weight: 500;
                    color: #33302d;
                }
            }

            .today-box {
                .today-item {
                    font-size: 14px;
                    font-family: PingFangSC-Regular, 'PingFang SC';
                    font-weight: 400;
                    color: #33302d;
                    margin-top: 16px;
                }
            }
        }
    }
}

.channel-code-stat-base-tooltip-content {
    width: 542px;
}
</style>
